package ducna.android.aoeclip.screen.category.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;

import ducna.android.aoeclip.R;
import ducna.android.aoeclip.common.model.entity.Category;

/**
 * Created by DUCNA on 11/7/2014.
 */
public class CategoryListAdapter extends RecyclerView.Adapter<CategoryListAdapter.ViewHolder> {
    private ArrayList<Category> listCategory;
    private int itemLayout;
    private Context context;

    public CategoryListAdapter(ArrayList<Category> listCategory, int itemLayout, Context context) {
        this.listCategory = listCategory;
        this.itemLayout = itemLayout;
        this.context = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(itemLayout, viewGroup, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int i) {
        Category category = listCategory.get(i);
        viewHolder.textViewCategoryTitle.setText(category.getCateName());
        Glide.with(context).load(category.getCateIcon()).placeholder(R.drawable.ic_launcher).centerCrop().into(viewHolder.imageViewCategoryIcon);
    }

    @Override
    public int getItemCount() {
        return listCategory == null ? 0 : listCategory.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public ImageView imageViewCategoryIcon;
        public TextView textViewCategoryTitle;

        public ViewHolder(View itemView) {
            super(itemView);
            imageViewCategoryIcon = (ImageView) itemView.findViewById(R.id.imageViewCategoryIcon);
            textViewCategoryTitle = (TextView) itemView.findViewById(R.id.textViewCategoryTitle);
        }
    }
}
